package com.ipet.cart.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ipet.cart.pojo.Cart;
import com.ipet.cart.service.CartService;
import com.ipet.common.vo.SysResult;


@RestController
@RequestMapping("/cart")
public class CartController {
	
	@Autowired
	private CartService cartService;
	
	private static ObjectMapper objectMapper = new ObjectMapper();
	

	@RequestMapping(method=RequestMethod.GET,value="/query/{userId}")
	public List<Cart> findCartByUserId(@PathVariable Long userId){
		return cartService.findCartByUserId(userId); 
		
	}
	
	//http://cart.jt.com/cart/update/num/{userId}/{itemId}/{num}
	@RequestMapping(value="/update"
			+ "",method=RequestMethod.POST)
	public void updateCartNum(@RequestBody Cart cart){
			cartService.updateCartNum(cart);
	}
	
	//http://cart.jt.com/cart/delete/{userId}/{itemId}
	@RequestMapping(value="/delete/{userId}/{itemId}",method=RequestMethod.GET)
	public void deleteCart(@PathVariable Long userId,@PathVariable Long itemId){
			cartService.deleteCart(userId,itemId);
	}
	
	//http://cart.jt.com/cart/save
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public void saveCart(@RequestBody Cart cart){
			cartService.saveCart(cart);
	}
	
}
